const express = require('express')
const cors = require('cors')
const loginRouter = require('./routes/login')
const estimateRouter = require('./routes/estimate')
const carmanagementRouter = require('./routes/carmanagement')
const customerRouter = require('./routes/customer')
const memberRouter = require('./routes/member')
const systemRouter = require('./routes/system')
const app = express()
//  设置端口为3000
app.listen(3000, () => {
    console.log('Link Start!');
})
//  使用cors组件解决跨域问题
app.use(cors())
//  post传参转对象
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/login', loginRouter)
app.use('/estimate', estimateRouter)
app.use('/carmanagement', carmanagementRouter)
app.use('/customer', customerRouter)
app.use('/member', memberRouter)
app.use('/system', systemRouter)
//  错误处理中间件
app.use(function (req, res, next) {
    res.send({ code: 400, msg: '资源不存在' })
});
app.use(function (err, req, res, next) {
    console.log(err)
    res.send({ code: 500, msg: '服务器端错误' })
});